<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class phieuchi_db 
	{
		public function Them($MaGiaoVien, $MaNguoiDung, $MaHopDong, $SoTien)
		{
			$sql = "INSERT INTO `tbl_phieuchi`(`MaGiaoVien`, `MaNguoiDung`, `MaHopDong`, `SoTien`)
					VALUES ('$MaGiaoVien', '$MaNguoiDung', '$MaHopDong', '$SoTien')";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaPhieuChi)
		{
			$sql = "DELETE FROM `tbl_phieuchi` WHERE `MaPhieuChi` = '$MaPhieuChi'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		public function XoaHopDong($MaHopDong)
		{
			$sql = "DELETE FROM `tbl_phieuchi` WHERE `MaHopDong` = '$MaHopDong'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaPhieuChi, $MaGiaoVien, $MaNguoiDung, $MaHopDong, $SoTien)
		{
			$sql = "UPDATE `tbl_phieuchi`
					SET `MaGiaoVien` = '$MaGiaoVien', `MaNguoiDung` = '$MaNguoiDung', `MaHopDong` = '$MaHopDong', `SoTien` = '$SoTien'
					WHERE `MaPhieuChi` = '$MaPhieuChi'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaPhieuChi, $MaGiaoVien, $MaNguoiDung, $MaHopDong, $SoTien)
		{
			$sql = "SELECT * FROM `tbl_phieuchi` WHERE 1  ";
			if($MaPhieuChi != -1)
				$sql .= " AND `MaPhieuChi` = '$MaPhieuChi' ";

			if($MaGiaoVien != "")
				$sql .= " AND `MaGiaoVien` = '$MaGiaoVien' ";

			if($MaNguoiDung != "")
				$sql .= " AND `MaNguoiDung` = '$MaNguoiDung' ";

			if($MaHopDong != -1)
				$sql .= " AND `MaHopDong` = '$MaHopDong' ";

			if($SoTien != -1)
				$sql .= " AND `SoTien` = '$SoTien' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

